<?php
include_once 'dao.php';
include_once 'configuracao_de_local.php';

class Design {
	
	private $raiz, $adicionar_body, $forms;
	
	public function Design($pastaraiz, $adicionar_body = "") {
		if (!isset($_SESSION)) {
			session_name("restauracao");
			session_start();
		}
		$this->raiz = $pastaraiz;
		$this->adicionar_body = $adicionar_body;
		$this->forms = array();
	}
	
	public function adicionar_form($id_form) {
		$this->forms[] = $id_form;
	}

	public function imprimir_topo($mostrar_menu = true, $mostrar_topo = true, $tem_que_estar_logado = true) {
		if (isset($_SESSION["logado"]) && $_SESSION["logado"] === true) {
			$usuario = $_SESSION["usuario"];
			$foto = "https://graph.facebook.com/".$_SESSION["id_usuario"]."/picture";
		}
		elseif ($tem_que_estar_logado) {
			header("Location: $this->raiz/login.php");
		}
		$numero = rand(1, 10);
		echo "
		 <html>
		 <head>
		 <meta http-equiv=\"X-UA-Compatible\" content=\"IE=8\" />
		 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
		 <title>Restauração</title>
		 <link rel=\"icon\" href=\"".$this->raiz."/img/favicon.ico\" type=\"image/x-icon\"> 
		 <link rel=\"stylesheet\" href=\"".$this->raiz."/css/estilo.css\" type=\"text/css\">
		 <link rel=\"stylesheet\" href=\"".$this->raiz."/css/base/jquery.ui.all.css\" type=\"text/css\">
		 <link rel=\"stylesheet\" href=\"".$this->raiz."/css/azul/jquery-ui-1.8.17.custom.css\" type=\"text/css\">
		 <link rel=\"stylesheet\" href=\"".$this->raiz."/css/colorbox.css\" type=\"text/css\">
		 </head>
		 <body ".$this->adicionar_body.">
		 <script src=\"".$this->raiz."/javascript/jquery-1.7.1.min.js\"></script>
		 <script src=\"http://connect.facebook.net/pt_BR/all.js\"></script>
		 <div id=\"fb-root\"></div>
		 <script>
		 jQuery('document').ready(function(){
			FB.init({
		";
		
		if (Configuracao_Local::eh_local()) {
			// offline
			echo "
					appId  : '242603499160670',
			";
		}
		else {
			// online
			echo "
					appId  : '228350447258983',
			";
		}
		
		echo "
				status : true, 
				cookie : true, 
				xfbml  : true 
			});
		";
		if ($tem_que_estar_logado) {
			echo "
			 FB.getLoginStatus(function(response) {
				if (response.status !== 'connected') {
					window.location.href = \"".$this->raiz."/logout.php\";
				}
			 });
			";
		}
		echo "
		 });
		 </script>
		";
		if ($mostrar_topo) {
			echo "
			 <div style=\"width: 100%; height: 150px; background-color: #006a25;\">
			 	<img src=\"".$this->raiz."/img/fundo$numero.jpg\" style=\"position: absolute; right: 450px; top: 0px; z-index: 1;\" /> 
				<a href=\"".$this->raiz."/index.php\"><img src=\"".$this->raiz."/img/restauracao.png\" style=\"z-index: 2; border-right: solid #006a25 150px; position: absolute; top: 0px; right: 0px;\"/></a>
			 </div>
			";
		}
		if ($mostrar_menu) {
			echo "
			 <div class=\"menu\">
				<table width=\"100%\">
				 	<tr>
				 		<td align=\"left\" style=\"background-color: #006a25;\">
			 				<a href=\"".$this->raiz."/musicas/index.php\"><img src=\"".$this->raiz."/img/musicas.png\" style=\"vertical-align: middle;\" /> Músicas</a> &nbsp;&nbsp;&nbsp;  
			 				<a href=\"".$this->raiz."/eventos/index.php\"><img src=\"".$this->raiz."/img/eventos.png\" style=\"vertical-align: middle;\" /> Eventos</a>
			 			</td>
			 			<td align=\"right\" style=\"color: #ffffff; background: #3b5998 url('".$this->raiz."/img/fundotransparente.png') no-repeat top left; padding-left: 80px; width: 1px; white-space: nowrap;\">
			 					Logado como <b>$usuario</b> &nbsp; <img src=\"$foto\" style=\"height: 30px; vertical-align: middle;\" />
			 			</td>
			 		</tr>
				</table>
		 	</div>
		 	";
		}
		echo "
			<div class=\"conteudo\"
		";
		if (!$mostrar_topo) {
			echo " style=\"min-height: 100%\"";
		}
		echo ">";
	}
	
	public function imprimir_fim($mostrar_rodape = true) {
		echo "
		 </div>
		";
		if ($mostrar_rodape) {
			echo "
			 <div class=\"rodape\">
				Desenvolvido por <a href=\"http://jpribeiro.com\" target=\"_blank\">João Paulo Ribeiro</a><br/>
				&nbsp;<a href=\"mailto: joaop.ribs@gmail.com\">joaop.ribs@gmail.com</a>&nbsp; | 
				&nbsp;<a href=\"http://jpribeiro.com\" target=\"_blank\">jpribeiro.com</a> 
			 </div>
			";
		}
		echo "
		 <script type=\"text/javascript\">
		";
		foreach ($this->forms as $id_form) {
			echo "iniciarForm(\"$id_form\");";
		}
		echo "
		 </script>
		 </body>
		 </html>
		";
	}
	
	public function get_imagem($nome_arquivo, $alt = '') {
		return "<img src=\"".$this->get_endereco_imagem($nome_arquivo)."\" alt=\"$alt\" />"; 
	}
	
	public function get_endereco_imagem($nome_arquivo) {
		return $this->raiz."/img/".$nome_arquivo;
	}
	
}